HAL CEC migration: List of applicable concepts

This section provides information about the HAL CEC applicable architecture concepts.

Concepts for CEC

Concept

Description

Separation of initialization and configuration functions

The Init and the config have been split into two level functions:

  • HAL_CEC_Init() that initializes the handle and links it to a CEC instance.

  • HAL_CEC_SetConfig() that configures the common CEC settings (own addresses configuration).

Removal and conversion of init structure to configuration structure

The init structure CEC_InitTypeDef has been removed from the handle and moved into the hal_cec_config_t configuration structure.

Renaming of the handle structure

The handle structure has been renamed to hal_cec_handle_t.

Renaming unitary init structures

The structure CEC_InitTypeDef structure has been replaced by hal_cec_config_t.

Remove MspInit and MspDeInit callbacks

HAL_CEC_MspInit() and HAL_CEC_MspDeInit() are no longer available they have been replaced by a user-defined sequence to initialize and configures the CEC.

Unitary configuration APIs

New APIs are available to get and set CEC features.

Introduction of HAL user data set/get APIs

Two functions to set/get user data are available HAL_CEC_SetUserData() and HAL_CEC_GetUserData().

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each CEC event. These functions are used to register callback functions for different CEC events.

Introduce specialized IRQ handlers

Keep IRQ Handler without splitting. Handle the CEC event and error interrupt requests with HAL_CEC_IRQHandler().

HAL implementation with LL inline functions

HAL CEC APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL CEC define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL CEC driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The CEC is now managed by six states: HAL_CEC_STATE_RESET, HAL_CEC_STATE_INIT, HAL_CEC_STATE_IDLE, HAL_CEC_STATE_RX_LISTEN, HAL_CEC_STATE_RX_ACTIVE and HAL_CEC_STATE_TX_ACTIVE.

Revised and optimized HAL API status returns

The HAL CEC functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

A dedicated function for error management has been added: HAL_CEC_GetLastErrorCodes().

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL CEC driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros.

Provide RTOS-compatible acquire/release bus services for communication peripheral drivers.

New HAL_CEC_AcquireBus() and HAL_CEC_ReleaseBus() functions are provided, allowing the acquisition and release of a HAL CEC handle to protect a full sequence.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

HAL CEC provides a new API to retrieve clock frequency HAL_CEC_GetClockFreq().

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including CEC instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Optimize HAL PPP IRQ Handlers by Reordering Processes and Error Management Statements to Prioritize Critical Interrupts

In HAL2, the implementation of HAL_CEC_IRQHandler() API has been improved to prioritize the handling of critical interrupts.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

HAL CEC resources and data structure start with the prefix HAL_CEC.

Other HAL CEC changes

Concept

Consideration

Introduce LL driver

In HAL2, new LL driver has been provided.

Introduce new APIs

Add the functions HAL_CEC_Start() and HAL_CEC_Start_IT(), which place the peripheral into listening mode in polling and interrupt modes respectively, instead of performing this operation within HAL_CEC_Init() as was done in HAL1.

Rework RX buffer setting API

The RX buffer setting API has been renamed from HAL_CEC_SetRxBuffer() to HAL_CEC_ChangeRxBuffer().

Introduce dedicated polling-mode APIs for both RX and TX operations

Add the HAL_CEC_PollForReception() and HAL_CEC_Transmit() functions which respectively handle polling for incoming data and transmitting data over the CEC bus.